package pri.black.garden.controller;

import java.util.List;
import java.util.Arrays;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pri.black.dogview.domain.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import pri.black.garden.domain.PlanLog;
import pri.black.garden.service.IPlanLogService;
import pri.black.garden.biz.PlanLogBiz;

/**
 * plan-logController
 * 
 * @author black
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/garden/plan-log")
public class PlanLogController
{
    @Autowired
    private PlanLogBiz planLogBiz;

    /**
     * 查询plan-log列表
     */
    //@PreAuthorize("@ss.hasPermi('garden:plan-log:list')")
    @GetMapping("/list")
    public R list(PlanLog query)
    {
        List<PlanLog> list = planLogBiz.getService()
                .lambdaQuery()
                .eq(PlanLog::getPlanId, query.getPlanId())
                .list();
        return R.ok(list);
    }

    @GetMapping("/logs")
    public R logs(Page<PlanLog> page,PlanLog query){
        return R.ok(planLogBiz.getService().selectPlanLogListPage(page, query));
    }

    /**
     * 获取plan-log详细信息
     */
    //@PreAuthorize("@ss.hasPermi('garden:plan-log:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        return R.ok(planLogBiz.getService().getById(id));
    }

    /**
     * 新增plan-log
     */
    //@PreAuthorize("@ss.hasPermi('garden:plan-log:add')")
    //@Log(title = "plan-log", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody PlanLog planLog)
    {
        return R.ok(planLogBiz.save(planLog));
    }

    /**
     * 修改plan-log
     */
    //@PreAuthorize("@ss.hasPermi('garden:plan-log:edit')")
    //@Log(title = "plan-log", businessType = BusinessType.UPDATE)
//    @PutMapping
    public R edit(@RequestBody PlanLog planLog)
    {
        return R.ok(planLogBiz.update(planLog));
    }

    /**
     * 删除plan-log
     */
    //@PreAuthorize("@ss.hasPermi('garden:plan-log:remove')")
    //@Log(title = "plan-log", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return R.ok(planLogBiz.getService().removeByIds(Arrays.asList(ids)));
    }
}
